package com.niconicod.ofb.actors;

import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Actor;

public class DebugBackground extends Actor {

    private Vector2 center;

    public DebugBackground() {
        center = new Vector2();
    }

    @Override
    public void act(float delta) {
        super.act(delta);
        Vector3 cameraPosition = getStage().getCamera().position;
        center.set(cameraPosition.x, cameraPosition.y);
    }

    @Override
    public void drawDebug(ShapeRenderer shapes) {
        super.drawDebug(shapes);
        int width = (int) getStage().getWidth();
        int height = (int) getStage().getHeight();

        int step = height / 10;

        int widthFrom = (int) center.x - width / 2 - width / 10;
        widthFrom -= widthFrom % step;
        int widthTo = (int) center.x + width / 2 + width / 10;

        int heightFrom = (int) center.y - height / 2 - height / 10;
        heightFrom -= heightFrom % step;
        int heightTo = (int) center.y + height / 2 + height / 10;

        float crossHalfSize = 0.2f;

        for (int w = widthFrom; w < widthTo; w += step) {
            for (int h = heightFrom; h < heightTo; h += step) {
                shapes.line(w - crossHalfSize, h - crossHalfSize, w + crossHalfSize, h + crossHalfSize);
                shapes.line(w - crossHalfSize, h + crossHalfSize, w + crossHalfSize, h - crossHalfSize);
            }
        }

    }
}
